//
//  NHUtils.m
//  LZNeiHan
//
//  Created by 梁梓烽 on 16/10/1.
//  Copyright © 2016年 liangzifeng. All rights reserved.
//

#import "NHUtils.h"
#import <MJRefresh/MJRefresh.h>
#import "MJRefreshComponent.h"
@implementation NHUtils

/** 开始下拉刷新 */
+(void)beginPulRefreshForScrollView:(UIScrollView *)scrollview
{
    [scrollview.mj_header beginRefreshing];
}


/** 停止下拉刷新 */
+(void)endRefreshForScrollView:(UIScrollView *)scrollview
{
    [scrollview.mj_header endRefreshing];
}

/** 停止上拉加载 */
+(void)endLoadMoreForScrollView:(UIScrollView *)scrollview
{
    [scrollview.mj_footer endRefreshing];
    
}
/** 判断头部是否在刷新 */
+(BOOL)headerIsRefreshForScrollView:(UIScrollView *)scrollview
{
    BOOL flag   = scrollview.mj_header.isRefreshing;
    
    return flag;
}
/** 判断尾部是否在刷新 */
+(BOOL)footerIsRefreshForScrollView:(UIScrollView *)scrollview
{
    BOOL flag = scrollview .mj_footer.isRefreshing;
    
    return flag;
    
}

/** 提示没有更多的数据 */
+(void)noticeNoMoreDataForScrollView:(UIScrollView *)scrollview
{

    [scrollview.mj_footer endRefreshingWithNoMoreData];
    
}

/** 重置footer */
+(void)resetNoMoreDataForScrollview:(UIScrollView *)scrollview
{
    [scrollview.mj_footer resetNoMoreData];
}


/** 隐藏header */
+(void)hiddenHeaderForScrollView:(UIScrollView *)scrollView
{
    scrollView.mj_header.hidden = YES;
}


/** 隐藏footer */
+(void)hiddenFooterForScrollView:(UIScrollView *)scrollView
{
    scrollView.mj_footer.hidden = YES;
}


/** 下拉刷新 */
+(void)addLoadMoreForScrollView:(UIScrollView *)scrollView loadMoreCallBack:(XRRefreshAndLoadMoreHandle)loadMoreCallBack
{
    if (scrollView == nil || loadMoreCallBack == nil) {
        return;
    }
    
    MJRefreshAutoNormalFooter *footer =[MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
        if (loadMoreCallBack) {
            loadMoreCallBack();
        }
    }];
    
    
    [footer setTitle:@"" forState:MJRefreshStateIdle];
    [footer setTitle:@"正在为你加载更多数据..." forState:MJRefreshStateRefreshing];
    [footer setTitle:@"没有加载到更多数据" forState:MJRefreshStateNoMoreData];
    footer.stateLabel.font = kFont(13);
    footer.stateLabel.textColor = kRGBColor(90, 90, 90);
    footer.backgroundColor  = kClearColor;
    
    scrollView.mj_footer = footer;
    
  
}

/** 上拉加载 */

+(void)addPullRefreshForScrollView:(UIScrollView *)scrollView pullRefreshCallBack:(XRRefreshAndLoadMoreHandle)
pullRefreshCallBack
{
    
    if (scrollView == nil || pullRefreshCallBack == nil) {
        return;
    }
    
    MJRefreshNormalHeader *header =[MJRefreshNormalHeader headerWithRefreshingBlock:^{
        if (pullRefreshCallBack) {
            pullRefreshCallBack();
        }
        
        if (scrollView.mj_footer.hidden == NO) {
            
            [scrollView.mj_footer resetNoMoreData];
        }
    }];
    
    [header setTitle:@"下拉刷新.." forState:MJRefreshStateIdle];
    [header setTitle:@"松开刷新.." forState:MJRefreshStatePulling];
    [header setTitle:@"正在刷新.." forState:MJRefreshStateRefreshing];
    
    header.stateLabel.textColor = kCommonBlackColor;
    header.stateLabel.font =kFont(13);
    
    header.lastUpdatedTimeLabel.hidden = YES;
    scrollView.mj_header = header;

    
    
}

@end
